Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Getting "Uncaught TypeError: callback is not a function" from using timeout with a callback

I want to do a callback with the calculator if successful, and I want it to catch the "Too High" error. But now when it throws the error all i get is "Uncaught TypeError: callback is not a function". No idea what I am doing wrong here

const calculator = (number, callback) => {
  setTimeout(() => {
    try { if (number > 3) Error('Too high')
      callback(null, number);
    } catch (err) {
      callback(err, null);
    }
  }, 888);
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I hope you are passing a callback as a param when calling the calculator function. If you want to catch the error Too High what you can do here instead is add the condition to the callback function you're passing as a param to the calculator function and return it from there since here your if condition is returning undefined. Actually, instead of adding the if one-line condition, use the && operator in the callback function, you are passing to return an error if a number is greater than 3. And just like T.J Crowder is saying you use throw Error('Too High').

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda